package com.woniuxy.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.woniuxy.entity.Role;
import com.woniuxy.entity.User;
import com.woniuxy.entity.Warehouse;
import com.woniuxy.service.WarehouseService;
import com.woniuxy.utils.Result;

@RestController
@RequestMapping("/warehouse")
public class WarehouseController {
	@Autowired
	private WarehouseService warehouseService;
	
	//查询所有仓库
	@GetMapping("/all")
	public List<Warehouse> findAllWarehouse(){
		
		List<Warehouse> warehouses = warehouseService.findAllWarehouse();
		
		return warehouses;
		}

	//根据状态查询仓库
	@GetMapping("/findwarehousebystatus")
	public Result<Object> findWarehouseByStatus(int status){
		Result<Object> result = new Result<>();
		if (status==1 || status==0) {
			List<Warehouse> warehouses = warehouseService.findWarehouseByStatus(status);
			if(warehouses==null) {
				result.setMessage("没有数据");
				return result;
			}
			result.setData(warehouses);
			return result;
		}
		result.setMessage("异常");
		return result;
	}
	//新增仓库--------------------存疑
	@GetMapping("/insert")
	public int insertRole(String rname,String rcode,int status,List<String>permission,String description) {
		Role newRole = new Role().setRname(rname).setRcode(rcode).setStatus(status).setPermission(permission).setDescription(description);
		return 0;
	}
	//根据关键字模糊查询仓库
	@GetMapping("/findwarehousebywords")
	public Result<Object> findByWords(String words){
		Result<Object> result = new Result<>();
		List<Warehouse> warehouse = warehouseService.findWarehouseByWords(words);
		if(warehouse==null) {
			result.setMessage("没有数据");
			return result;
		}
		result.setData(warehouse);
		return result;
	}
	//删除仓库
	@GetMapping("/delbywid")
	public Result<Object> delByRid(int wid) {
		warehouseService.delByWid(wid);
		List<Warehouse> warehouses = warehouseService.findAllWarehouse();
		Result<Object> result = new Result<>();
		result.setData(warehouses);
		result.setMessage("删除仓库成功");
		return result;
	}
	
}
